package groupon.common.util;

import groupon.commom.model.Navigation;
import groupon.commom.model.NavigationItem;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


public class MainNavigationItemBean implements InitializingBean,
		ApplicationContextAware {

	private ApplicationContext _applicationContext = null;
	private String _name;
	private String _href;
	private String _key;
	private List<NavigationItem> _items;
	private String _mainNavigationBean;
	

	@Required
	public String getName() {
		return _name;
	}

	public void setName(String name) {
		_name = name;
	}

	public String getKey() {
		return _key;
	}

	@Required
	public void setKey(String key) {
		_key = key;
	}

	public List<NavigationItem> getItems() {
		return _items;
	}

	public void setItems(List<NavigationItem> items) {
		_items = items;
	}

	public void setApplicationContext(ApplicationContext actx)
			throws BeansException {
		_applicationContext = actx;
	}

	public String getHref() {
		return _href;
	}

	@Required
	public void setHref(String href) {
		_href = href;
	}

	public void afterPropertiesSet() throws Exception {
		MainNavigationBean mainNavigation = (MainNavigationBean) _applicationContext
				.getBean(_mainNavigationBean);
		List<Navigation> navs = mainNavigation.getListNavigations();
		Navigation nav = new Navigation();
		nav.setName(_name);
		nav.setHref(_href);
		nav.setKey(_key);
		nav.setItems(_items);
		navs.add(nav);
	}

	public String getMainNavigationBean() {
		return _mainNavigationBean;
	}

	@Required
	public void setMainNavigationBean(String mainNavigationBean) {
		_mainNavigationBean = mainNavigationBean;
	}
}
